package io.tij;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Date;

import util.Constants;


import static util.Print.*;

public class Logon implements Serializable{

	private String username;
	// password will not be serialized
	private transient String password;
	private Date date = new Date();

	public Logon(String username, String password) {
		this.username = username;
		this.password = password;
	}

	public String toString() {
		return "logon info: \n   username: " + username + "\n   date: " + date
				+ "\n   password: " + password;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException, ClassNotFoundException{
		final String filepath = Constants.IO_FILE_BASE_PATH + "Logon.out";

		Logon a = new Logon("Roy.Yang", "pass");
		print("Logon a = " + a);
		
		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filepath));
		out.writeObject(a);
		out.close();
		
		ObjectInputStream in = new ObjectInputStream(new FileInputStream(filepath));
		a = (Logon) in.readObject();
		in.close();
		
		print("After recovered: Logon a =" + a);

	}

}
